﻿using Polenter.Serialization;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace App1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    /// 

    public sealed partial class MainPage : Page
    {
        public MyViewModel DefaultViewModel;
        public MainPage()
        {
            // ApplicationData.Current.ClearAsync();
            DefaultViewModel = new MyViewModel();
            this.InitializeComponent();
            this.DataContext = DefaultViewModel;
        }

        private void ButtonOpen_Click(object sender, RoutedEventArgs e)
        {

            foreach (var item in DefaultViewModel.Favorites)
            {
                Debug.WriteLine(item.Url);
            }
        }

        private void ButtonFavorite_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine(DefaultViewModel.NewPage.Key);
            Debug.WriteLine(DefaultViewModel.NewPage.Key);
            Debug.WriteLine(DefaultViewModel.NewPage.Key);
            Debug.WriteLine(DefaultViewModel.NewPage.Url);
            var fav = new Favorite();
            fav.LoadFrom(DefaultViewModel.NewPage);
            Debug.WriteLine(fav.Key);
            Debug.WriteLine(fav.Url);
            DefaultViewModel.Favorites.Add(fav);
            Debug.WriteLine(fav.Key);
            Debug.WriteLine(fav.Url);

        }

        private void ButtonNew_Click(object sender, RoutedEventArgs e)
        {
            DefaultViewModel.NewPage = new Favorite();
            DefaultViewModel.NewPage.Clear();
            DefaultViewModel.NewPage.Key = Guid.NewGuid().ToString();
            DefaultViewModel.NewPage.Container = ApplicationData.Current.RoamingSettings.CreateContainer("NewPage", ApplicationDataCreateDisposition.Always);
        }

    }

}
